package edu.ynu.se.xiecheng.achitectureclass.project.service;

import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.project.dao.DeviceDao;
import edu.ynu.se.xiecheng.achitectureclass.project.po.entity.Device;
import edu.ynu.se.xiecheng.achitectureclass.project.po.vo.DeviceVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@Slf4j
public class DeviceService extends LogicService<DeviceDao, Device, Long> {
    public DeviceService(DeviceDao dao) {
        super(dao);
    }

    public List<DeviceVO> getAllDevicesStatus() {
        List<Device> devices = dao.findAllByIsDeletedIsFalse();
        return devices.stream()
                .map(this::convertToDeviceVO)
                .collect(Collectors.toList());
    }

    private DeviceVO convertToDeviceVO(Device device) {
        DeviceVO vo = new DeviceVO();
        vo.setDeviceId(device.getDeviceId());
        vo.setName(device.getName());
        if (device.getGreenhouse() != null) {
            vo.setGreenhouseName(device.getGreenhouse().getName());
        }
        return vo;
    }


}
